package com.example.rabbitmq.controller;

import com.example.rabbitmq.service.DelayMessageService;
import com.example.rabbitmq.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MessageController {

    @Autowired
    private MessageService messageService;

    @Autowired
    private DelayMessageService delayMessageService;


    /**
     * 发送普通消息
     *
     * @param message
     * @return
     */
    @GetMapping("/send")
    public String sendMessage(@RequestParam String message) {
        messageService.sendMessage(message);
        return "消息发送成功";
    }

    /**
     * 发送延迟消息
     *
     * @param message
     * @param delayMillis
     * @return
     */
    @GetMapping("/sendDelay")
    public String sendDelayMessage(@RequestParam String message, @RequestParam long delayMillis) {
        delayMessageService.sendDelayMessage(message, delayMillis);
        return "延迟消息发送成功，延迟时间：" + delayMillis + "ms";
    }

}
